package org.com.ffy.controller;

import org.com.ffy.model.Restaurant;
import org.com.ffy.service.RestaurantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
public class RestaurantController {

    // 假设有一个静态的餐厅列表用于测试
    private static final List<Restaurant> restaurants = List.of(
            new Restaurant("惊喜餐厅", "市中心", "特色美食"),
            new Restaurant("美味餐厅", "郊区", "家常菜"),
            new Restaurant("豪华餐厅", "海滨", "海鲜")
    );
    @GetMapping("/restaurants")
    public List<Restaurant> getRestaurants() {
        return restaurants;
    }
    // 新增的方法，用于测试@RequestParam注解
    @GetMapping("/restaurant")
    public List<Restaurant> getRestaurantByName(@RequestParam String name) {
        List<Restaurant> result = new ArrayList<>();
        for (Restaurant restaurant : restaurants) {
            if (restaurant.getName().equalsIgnoreCase(name)) {
                result.add(restaurant);
            }
        }
        return result;
    }
    @PostMapping("/restaurant")
    public Restaurant createRestaurant(@RequestBody Restaurant restaurant) {
        restaurants.add(restaurant);
        return restaurant;
    }

}